import java.io.*;
import org.apache.poi.hpsf.*;
import org.apache.poi.poifs.eventfilesystem.*;

import java.util.*;

public class ReadOfficeSummary {
  public static void main(String[] args)
      throws IOException {  
    final String filename = args[0];
    POIFSReader r = new POIFSReader();
    r.registerListener(new SummaryReaderListener(),
                       "\005SummaryInformation");
    r.registerListener(new DocumentSummaryReaderListener(),
                       "\005DocumentSummaryInformation");                       
    r.read(new FileInputStream(filename));
  }
}

class SummaryReaderListener implements POIFSReaderListener {
  public void processPOIFSReaderEvent(POIFSReaderEvent event) {
    SummaryInformation si = null;
    try {
        si = (SummaryInformation)
             PropertySetFactory.create(event.getStream());
    }
    catch (Exception ex) {
        throw new RuntimeException
            ("Property set stream \"" +
             event.getPath() + event.getName() + "\": " + ex);
    }
    String title = si.getTitle();
    if (title != null)
        System.out.println("Title: \"" + title + "\"");
    else
        System.out.println("Document has no title.");
    
    
    
    title = si.getApplicationName();
    System.out.println("ApplicationName: \"" + title + "\"");
    
    title = si.getAuthor();
    System.out.println("Author: \"" + title + "\"");
    
    int n = si.getCharCount();
    System.out.println("CharCount: \"" + n + "\"");
    
    title = si.getComments();
    System.out.println("Comments: \"" + title + "\"");
    
    Date ddate = si.getCreateDateTime();
    System.out.println("CreateDateTime: \"" + ddate + "\"");
    
    ddate = si.getEditTime();
    System.out.println("EditTime: \"" + ddate + "\"");
    
    title = si.getKeywords();
    System.out.println("Keywords: \"" + title + "\"");
    
    title = si.getLastAuthor();
    System.out.println("LastAuthor: \"" + title + "\"");
    
    ddate = si.getLastPrinted();
    System.out.println("LastPrinted: \"" + ddate + "\"");
    
    ddate = si.getLastSaveDateTime();
    System.out.println("LastSaveDateTime: \"" + ddate + "\"");    
    
    n = si.getPageCount();
    System.out.println("PageCount: \"" + n + "\"");
    
    title = si.getRevNumber();
    System.out.println("RevNumber: \"" + title + "\"");
    
    n = si.getSecurity();
    System.out.println("Security: \"" + n + "\"");
    
    title = si.getSubject();
    System.out.println("Subject: \"" + title + "\"");
    
    title = si.getTemplate();
    System.out.println("Template: \"" + title + "\"");
    
    n = si.getWordCount();
    System.out.println("WordCount: \"" + n + "\"");
  }
}

class DocumentSummaryReaderListener implements POIFSReaderListener {
  public void processPOIFSReaderEvent(POIFSReaderEvent event) {
    DocumentSummaryInformation si = null;
    try {
        si = (DocumentSummaryInformation)
             PropertySetFactory.create(event.getStream());
    }
    catch (Exception ex) {
        throw new RuntimeException
            ("Property set stream \"" +
             event.getPath() + event.getName() + "\": " + ex);
    }
    String str = null;

    str = si.getCompany();
    System.out.println("Company: \"" + str + "\"");
    
    str = si.getManager();
    System.out.println("Manager: \"" + str + "\"");
    
    str = si.getCategory();
    System.out.println("Category: \"" + str + "\"");
  }
}